package com.llb666.shop.items.infrastructure.persistence;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.llb666.common.core.utils.page.PagedGridResult;
import com.llb666.shop.items.api.dto.OrderItemsCommentDto;
import com.llb666.shop.items.domain.entity.ItemsComments;
import com.llb666.shop.items.domain.entity.bo.MyCommentBo;
import com.llb666.shop.items.domain.repository.ItemsCommentsRepository;
import com.llb666.shop.items.infrastructure.conver.ItemsCommentsCvt;
import com.llb666.shop.items.infrastructure.mapper.ItemsCommentsMapper;
import com.llb666.shop.items.infrastructure.po.ItemsCommentsPo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 我的评论.
 *
 * @author llb666
 */
@Repository
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class ItemsCommentsRepositoryImpl implements ItemsCommentsRepository {

    private final ItemsCommentsMapper itemsCommentsMapper;

    @Override
    public void saveComments(String userId, List<OrderItemsCommentDto> commentList) {
        Map<String, Object> map = new HashMap<>();
        map.put("userId", userId);
        map.put("commentList", commentList);
        itemsCommentsMapper.saveComments(map);
    }


    /**
     * 查询我的评论.
     *
     * @param userId   用户id
     * @param page     当前页
     * @param pageSize 每页显示数量
     * @return 我的评论列表
     */
    @Override
    public PagedGridResult<MyCommentBo> queryMyComments(String userId, Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);
        List<MyCommentBo> myCommentBos = itemsCommentsMapper.queryMyComments(userId);
        PageInfo<MyCommentBo> myCommentBoPageInfo = new PageInfo<>(myCommentBos);
        return PagedGridResult.setterPagedGrid(myCommentBoPageInfo);
    }

}
